<?php
	$css_list[0]['url'] = './tpl/css/album.css';
	$js_list[0] = './tpl/js/album.js';
	$js_list[1] = './public/js/jquery.masonry.js';
?>
<!--{template inc/header}-->
<div id="body" class="fm960"> 
	<div class="album_subnav">
		<!--{loop $_FANWE['cache']['albums']['category'] $category}-->
		<!--{if $category['id'] == $album_cate['id']}-->
		<a href="{$category['url']}" title="{$category['name']}"><img src="{$category['img_hover']}" /></a>
		<!--{else}-->
		<a href="{$category['url']}" title="{$category['name']}"><img src="{$category['img']}" /></a>
		<!--{/if}-->
		<!--{/loop}-->
	</div>
	<div class="imagewall_sort">
		<div class="fl" style="margin-left:0" >
			<a>排序：</a>
			<a href="{u album/category id=$album_cate['id'],sort=new}"{if $sort == 'new'} class="c"{/if}>最新</a>
			<a href="{u album/category id=$album_cate['id'],sort=hot}"{if $sort == 'hot'} class="c"{/if}>最热</a>
		</div>
	</div>
	<div class="blank12"></div>
	<div id="album_container" class="albumwall album_td">
		<!--{loop $share_list $share}-->
		<div class="album_list_t hide1" shareID="{$share['share_id']}" id="SHARE_LIST_{$share['share_id']}">
			<div class="hd"></div>
			<div class="bd">
				<ul class="pic">
					<!--{loop $share['imgs'] $share_img}-->
					<li>
						<a href="{u album/show id=$share['rec_id'],sid=$share['share_id']}" target="_blank"><img class="book_img lazyload" original="{getimg $share_img['img'] 200 999}" src="./tpl/images/lazyload.gif" oldWidth="{$share_img['img_width']}" oldHeight="{$share_img['img_height']}"></a>
						<!--{if $share_img['type'] == 'g'}-->
						<span class="p">
							<span>
								<b>{$share_img['price_format']}</b>
							</span>
							<i></i>
						</span>
						<!--{/if}-->
					</li>
					<!--{/loop}-->
				</ul>
				<!-- 喜欢 -->
				<div class="favorite">
					<a href="javascript:;" class="favaImg" onclick="$.Fav_Share({$share['share_id']},this,32,'#SHARE_LIST_{$share['share_id']}');">喜欢</a>
					<div class="favDiv"> <a target="_blank" class="favCount SHARE_FAV_COUNT" href="{$share['url']}">{$share['collect_count']}</a><i></i></div>
					<span class="creply_n"> (<a href="{$share['url']}" target="_blank">{$share['comment_count']}</a>)</span>
					<a href="{$share['url']}" class="creply">评论</a>
				</div>
				<!-- 原推内容 -->
				<div class="who_share">
					<div class="tk clearfix">
						<!--{if !empty($share['content']) && $share['content'] != $share['empty_content']}-->
						<p>{cutstr $share['content'] 96}</p>
						<!--{/if}-->
						<span class="share_mf"> </span>
					</div>
					<div class="ws_bd clearfix">
						<!--{getuser $share['uid'] 0 'm,48' ',icard avt fl r3 lazyload'}-->
						<div class="user_info">
							<!--{getuser $share['uid'] 0 '' 'n icard'}--> <span class="add_album_u">加入{lang common/album}</span><br />
							<a target="_blank" href="{u album/show id=$share['rec_id']}" class="share_album_n">《{cutstr $share['title'] 16}》</a>
						</div>
					</div>
				</div>
			</div>
			<!-- 评论 -->
			<!--{if !empty($share['comments'])}-->
			<ul class="rep_list">
				<!--{loop $share['comments'] $comment}-->
				{if $comment['uid']}
				<li class="rep_f">
					<!--{getuser $comment['uid'] 0 's,24' ',avt icard fl r3 lazyload'}-->
					<p class="colg">
						<!--{getuser $comment['uid'] 0 '' 'n icard fl'}-->：{$comment['content']}
					</p>
				</li>
				{/if}
				<!--{/loop}-->
			</ul>
			<!--{/if}-->
			<div class="ws_ft"></div>
		</div>
		<!--{/loop}-->
	</div>
	<div class="blank12"></div>
	<!--{if $pager['page_count'] > 1}-->
	<div class="pagination hide" id="pageBox">
		<!--{subtemplate inc/pages}--> 
	</div>
	<!--{/if}-->
</div>
<div id="pbLoading" style="background:url(./tpl/images/loading.gif) no-repeat center center;height:52px; display:none;"></div>
<div class="hide">
<!--{if $pager['page_count'] > 0}-->
<!--{loop $pb_list $url}-->
<a href="{$url}">{$url}</a>
<!--{/loop}-->
<!--{/if}-->
</div>
<script type="text/javascript">
var rowHtml = '<div class="album_list_t empty_row"><div class="hd"></div><div class="bd" style="height:#HEIGHT#px;"></div><div class="ws_ft"></div></div>';
var pbUrl = "{$pb_url}";
var imgWidth = 200;
var pbMaxIndex = {$_FANWE['setting']['share_pb_load_count']};

jQuery(function(){
	<!--{if getIsManage('album')}-->
	$('.album_list_t').live('mouseover',function(){
		var shareID = this.getAttribute('shareID');
		if(shareID)
			$.GetManageMenu('album',shareID,this);
	});
	<!--{/if}-->
	
	$(".book_img").each(function(){
		var oldWidth = parseInt(this.getAttribute("oldWidth"));
		var oldHeight = parseInt(this.getAttribute("oldHeight"));
		if(isNaN(oldWidth) || isNaN(oldHeight) || oldWidth == 0 || oldHeight == 0)
		{
			this.height = 0;
		}
		else
		{
			var scale = imgWidth / oldWidth;
			this.height = oldHeight * scale;
		}
	});

	$('#album_container').css({"height":"auto","background":"none"});
	$('.album_list_t').css("visibility","visible");
	
	$('#album_container').masonry({
		itemSelector: '.album_list_t',
		isAnimated:true,
		gutterWidth:15,
		gutterHeight:8,
		columnWidth:225
	});
	
	<!--{if $pager['page_count'] > 0}-->
	createPBScroll(pbUrl,appendShareItem,pbLoadingFun,2,pbMaxIndex,300);
	<!--{/if}-->
});

function appendBottomItem()
{
	var lefts = new Object();
	var colTotal = 4;
	$(".album_list_t").each(function(i){
		if($(this).position().top == 0)
		{
			lefts['l'+$(this).position().left] = $(this);
		}
		else
		{
			if(lefts['l'+$(this).position().left].position().top <  $(this).position().top)
				lefts['l'+$(this).position().left] = $(this);
		}
	});
	
	var cols = 0;
	var maxLeft = '';
	var currentSize = 0;
	var maxSize = 0;
	for(var left in lefts)
	{
		cols++;
		currentSize = lefts[left].position().top + lefts[left].height();
		if(currentSize > maxSize)
		{
			maxLeft = left;
			maxSize = currentSize;
		}
	}
	
	var htmlArray = new Array();
	var htmlObjs = new Object();
	html = '';
	for(var left in lefts)
	{
		currentSize = lefts[left].position().top + lefts[left].height();
		if(currentSize < maxSize)
		{
			htmlObjs['h'+(maxSize - currentSize)] = rowHtml.replace("#HEIGHT#",maxSize - currentSize - 30);
			htmlArray.push(maxSize - currentSize);
		}
	}

	var newArray = htmlArray.sort(function(a,b){
		if(a > b)
			return -1;
		else if(a < b)
			return 1;
		else
			return 0;
	});
	
	for(var h=0;h<newArray.length;h++)
	{
		html += htmlObjs['h'+newArray[h]];
	}

	if(colTotal > cols)
	{
		for(var i=0; i< (colTotal - cols);i++)
		{
			html = rowHtml.replace("#HEIGHT#",maxSize - 22) + html;
		}
	}
	html = $('<div>' + html + '</div>').find('.album_list_t');
	$('#album_container').append(html).masonry('appended',html,true);
}

function appendShareItem(result,index)
{
	html = '<div>' + result + '</div>';
    html = $(html).find('.album_list_t');
	$(".book_img",html).each(function(){
		var oldWidth = parseInt(this.getAttribute("oldWidth"));
		var oldHeight = parseInt(this.getAttribute("oldHeight"));
		if(isNaN(oldWidth) || isNaN(oldHeight) || oldWidth == 0 || oldHeight == 0)
		{
			this.height = 0;
		}
		else
		{
			var scale = imgWidth / oldWidth;
			this.height = oldHeight * scale;
		}
	});
	$('#album_container').append(html).masonry('appended',html,true,function(){
		if(index >= pbMaxIndex || result == '')
		{
			$("#pageBox").show();
			var fun = function(){
				appendBottomItem();
			}
			setTimeout(fun,1000);
		}
	});
}

function pbLoadingFun(bln)
{
	if(bln)
		$("#pbLoading").show();
	else
		$("#pbLoading").hide();
}
</script>
<!--{template inc/footer}-->
